package com.zzyl.common.utils.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 22 5月 2025 01:25
 */
@Component
@Slf4j
public class AIModelInvoker {

    @Value("${qianfan.model}")
    private String model;
    @Value("${qianfan.temperature}")
    private String temperature;

    //返回值是Json类型
    public String qianfanInvoker(String prompt) {
        // 指定模型
        ChatResponse resp = new Qianfan().chatCompletion()
                .model(model)
                .addMessage("user", prompt)
                .temperature(Double.valueOf(temperature))
                .responseFormat("json_object")
                .execute();
        return resp.getResult();
    }
}

